package com.wty.love;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.wty.love.loveTalk.LoveTalkActivity;
import com.wty.love.smallGames.SmallGamesActivity;
import com.wty.love.smallGames.WebActivity;
import com.wty.love.utils.Lunar;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.TimeZone;

public class NewMainActivity extends AppCompatActivity {

    private String nBirthday = "七月十七";

    private TextView note;
    private TextView loveTalk;
    private TextView smallGames;
    private View confessionWeb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_main);
        initView();
        initData();
        initClick();
    }

    private void initView(){
        note = findViewById(R.id.note);
        loveTalk = findViewById(R.id.loveTalk);
        smallGames = findViewById(R.id.smallGames);
        confessionWeb = findViewById(R.id.confessionWeb);
    }

    private void initClick(){
        note.setOnClickListener(v->{
            Intent intent = new Intent(this,MainActivity.class);
            startActivity(intent);
        });
        loveTalk.setOnClickListener(v->{
            Intent intent = new Intent(this, LoveTalkActivity.class);
            startActivity(intent);
        });
        smallGames.setOnClickListener(v->{
            Intent intent = new Intent(this, SmallGamesActivity.class);
            startActivity(intent);
        });
        confessionWeb.setOnClickListener(v->{
            Toast.makeText(this,"滑动一下呀，最好缩小点页面~❤",Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(this, WebActivity.class);
            intent.putExtra(WebActivity.URL,WebActivity.url520);
            startActivity(intent);
        });
    }

    private void initData(){
        //特殊节日弹窗
        specialFestivalsDialog();
    }

    private void specialFestivalsDialog() {
        Calendar cal=Calendar.getInstance();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日");
        cal.setTimeZone(TimeZone.getDefault());
        System.out.println("公历日期:"+sdf.format(cal.getTime()));
        Lunar lunar=new Lunar(cal);
        System.out.println("*************");
        String str = lunar.toString();
        System.out.println("当前农历日期:"+str);
        System.out.println("农历生日:"+nBirthday);
        System.out.println();
        if (str.contains(nBirthday)){
            AlertDialog alertDialog = new AlertDialog.Builder(this)
                    .setTitle("猜猜今天是什么日子呢")//标题
                    .setMessage(getString(R.string.birthdayStr))//内容
                    .create();
            alertDialog.show();
        }else if (str.contains("七月初七")){
            AlertDialog alertDialog = new AlertDialog.Builder(this)
                    .setMessage("七夕啦今天，有没有想我呀")//内容
                    .create();
            alertDialog.show();
        }else if ( sdf.format(cal.getTime()).toString().contains("5月20") ){
            AlertDialog alertDialog = new AlertDialog.Builder(this)
                    .setTitle("520😘")
                    .setMessage("爱你是每一天的事情，不会因为今天不是特殊日子而减少，反倒是会因此增加，有你在我身边真是世界上最幸福的事")//内容
                    .create();
            alertDialog.show();
        }else if ( sdf.format(cal.getTime()).toString().contains("3月26") ){
            AlertDialog alertDialog = new AlertDialog.Builder(this)
                    .setTitle("记录我们在一起的那一天")
                    .setMessage("从我们开始聊天的那一天，从我们慢慢变得从陌生到熟悉，从第一次约会，从第一次拥抱，第一次牵手到现在，我变得越来越喜欢你，越来越离离不开你，有你在，我就是世界上最幸福的人")//内容
                    .create();
            alertDialog.show();
        }
    }
}